# -*- coding:utf-8 -*-
import logging
import requests
import yaml
from faker import Faker


def read_yaml():
    """
    读取环境配置信息
    :return:
    """
    with open(r"../data/data_yaml.yml", "r", encoding="utf-8")as f:
        env = yaml.safe_load(f)
    logging.info("读取环境配置信息")
    return env
def read_add_send_yaml():
    """
    读取环境配置信息
    :return:
    """
    with open(r"../data/add_send_yaml.yml", "r", encoding="utf-8")as f:
        data = yaml.safe_load(f)
    logging.info("新增人员接口")
    return data

def get_token():
    """
    获取token
    :return:
    """
    corpid = "ww0e005a984a50a3a7"
    corpsecret = "PWJNqCfLezTNfzlWgGQZ3Gl1E0y59rI84Kg2N8gkfok"
    url = f"https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={corpid}&corpsecret={corpsecret}"
    r = requests.get(url=url, verify=False)
    logging.info(f"获取token:{r.json()['access_token']}")
    return r.json()['access_token']


def get_faker():
    """
    获取faker数据
    :return:
    """
    faker = Faker("zh_CN")
    name = faker.name()  # 名字
    userid = faker.numerify()  # 随机3位数字
    phone = faker.phone_number()  # 手机号
    address = faker.address()  # 详细地址
    email = faker.email()  # 邮箱
    position = "测试工程师"  # 职务
    datas = {
        "get_name": name,
        "get_userid": f"2021{userid}",
        "get_phone": phone,
        "get_address": address,
        "get_email": email,
        "get_position": position
    }
    return datas
